<template>
  <div
    style="
      background: #f5f5f5;
      overflow: hidden;
      position: relative;
      height: 100vh;
    "
    v-loading="loading"
  >
    <div class="applyHeade">
      <span class="back">
        <i
          v-if="http.indexOf('dkaq') == -1 || http.indexOf('xcaq') == -1"
          class="el-icon-arrow-left"
          @click="
            () => {
              this.$router.push('/');
            }
          "
        >
        </i>
      </span>
      <span> 在线报名 </span>
      <!--  @click="login" -->
      <el-button class="button" @click="login">立即登录</el-button>
    </div>
    <div class="tableBody">
      <div
        style="
          width: 100%;
          height: 100%;
          overflow: auto;
          overflow-x: hidden;
          background: #eeeeee;
        "
      >
        <div class="form">
          <field
            v-model="gz"
            label="培训大类"
            fildType="select"
            :readonly="true"
            :columns="GZList"
            placeholder="请选择"
            filed_id="gz"
          ></field>
        </div>
        <template
          v-if="
            http.indexOf('taihua') == -1 ||
            (http.indexOf('taihua') != -1 && formLabelAlign.gz != '学历提升')
          "
        >
          <div v-for="(item, index) in fromList" :key="index + 9999999999">
            <div
              class="form"
              v-show="item.passShow"
              v-if="
                ['select', 'input', 'number', 'textarea'].includes(
                  item.field_type
                )
              "
            >
              <field
                :label="item.label"
                :fildType="item.field_type"
                v-model="formLabelAlign[item.field_id]"
                :filed_id="item.field_id"
                :readonly="item.field_type == 'select'"
                :columns="options[item.field_id]"
                @change="changefiled"
                :requires="item.selected"
                :placeholder="item.hint"
              >
                <div
                  v-if="item.field_id == 'username' && photoApply"
                  slot="button"
                >
                  <upload
                    type="id_card_photo"
                    label="拍 照"
                    @change="uploadChange"
                    :zip="true"
                    :button="true"
                    :corp="false"
                    style="width: 54px; margin-right: 12px"
                  ></upload>
                </div>
              </field>
            </div>
            <div
              class="form"
              v-show="item.passShow"
              v-else-if="item.field_type == 'img'"
            >
              <div style="padding: 0 12px" v-if="item.field_id != 'id_card'">
                <p
                  style="
                    margin-bottom: 12px;
                    font-size: 16px;
                    position: relative;
                  "
                >
                  <i class="require" v-if="Boolean(item.selected)">*</i
                  >{{ item.label }}
                </p>
                <span
                  style="
                    color: #999;
                    font-size: 13px;
                    line-height: 1.5;
                    margin-bottom: 12px;
                    display: block;
                  "
                  v-if="item.field_id != 'photo'"
                >
                  {{ item.hint }}
                </span>
                <upload
                  :type="item.field_id"
                  :label="item.label"
                  @change="uploadChange"
                  :zip="true"
                  :tips="item.hint"
                ></upload>
              </div>
              <div style="padding: 0 12px" v-else>
                <p style="margin-bottom: 12px; font-size: 16px">
                  {{ item.label }}
                </p>
                <span
                  style="
                    color: #999;
                    font-size: 13px;
                    line-height: 1.5;
                    margin-bottom: 12px;
                    display: block;
                  "
                >
                  {{ item.hint }}
                </span>
                <div style="display: flex">
                  <div>
                    <upload
                      type="id_card_photo"
                      label="身份证人像面"
                      @change="uploadChange"
                      :zip="true"
                      :value="formLabelAlign['id_card_photo']"
                    ></upload>
                  </div>
                  <div>
                    <upload
                      style="margin-left: 12px"
                      type="id_card_emblem"
                      label="身份证国徽面"
                      @change="uploadChange"
                      :zip="true"
                    ></upload>
                  </div>
                </div>
              </div>
            </div>
            <div
              class="form"
              v-show="item.passShow"
              v-else-if="['datetime'].includes(item.field_type)"
            >
              <field
                :label="item.label"
                :fildType="item.field_type"
                v-model="formLabelAlign[item.field_id]"
                :filed_id="item.field_id"
                :readonly="true"
                @change="changefiled"
                :requires="item.selected"
                :placeholder="item.hint"
              >
              </field>
            </div>
            <div
              class="form"
              v-show="item.passShow"
              v-else-if="['datetimeRange'].includes(item.field_type)"
            >
              <field
                :label="item.label"
                :fildType="item.field_type"
                v-model="formLabelAlign[item.field_id][0]"
                :filed_id="item.field_id"
                :readonly="true"
                @change="changefiled"
                arrangement="column"
                style="width: 50%"
                placeholder="请选择开始日期"
                :requires="item.selected"
              >
              </field>
              <field
                :requires="false"
                style="width: 50%"
                label="-"
                labelWidth="auto"
                :fildType="item.field_type"
                v-model="formLabelAlign[item.field_id][1]"
                :filed_id="item.field_id"
                :readonly="true"
                @change="changefiled"
                placeholder="请选择结束日期"
              >
              </field>
            </div>
            <div
              class="form"
              v-show="item.passShow"
              v-else-if="['sign', 'autowrite'].includes(item.field_type)"
            >
              <div style="padding: 0 12px; width: 100%">
                <div
                  style="
                    margin-bottom: 12px;
                    display: flex;
                    justify-content: space-between;
                  "
                >
                  <p style="font-size: 16px; position: relative">
                    <i class="require" v-if="Boolean(item.selected)">*</i
                    >{{ item.label }}
                  </p>
                  <span
                    style="font-size: 14px; color: #166aff"
                    @click.stop="openBookalert(item, item.label)"
                    >阅读{{ item.label }}</span
                  >
                </div>
                <sign
                  :field_id="item.field_id"
                  :field_type="item.field_type"
                  v-model="showsign"
                  @update="
                    ({ signsrc, signature }) => {
                      formLabelAlign[item.field_id] = signsrc;
                      formLabelAlign.signature = signature;
                    }
                  "
                  @openSign="openSign(item, $event)"
                  :formLabelAlign="formLabelAlign"
                  :subjectTittle="subjectTittle"
                ></sign>
              </div>
            </div>
            <div
              class="form"
              v-show="item.passShow"
              v-else-if="['download'].includes(item.field_type)"
            >
              <div
                style="
                  display: flex;
                  width: 100%;
                  height: 40px;
                  align-items: center;
                "
              >
                <p
                  style="
                    font-size: 16px;
                    display: block;
                    width: 80px;
                    position: relative;
                  "
                >
                  <i class="require" v-if="Boolean(item.selected)">*</i
                  >{{ item.label }}
                </p>
                <div
                  style="
                    flex: 1;
                    height: 40px;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    color: #fff;
                    background: #166aff;
                    border-radius: 4px;
                  "
                  @click="downFuled(item.others.appendix)"
                >
                  附件下载
                </div>
              </div>
            </div>
          </div>
        </template>
        <template v-else>
          <Taihua ref="taihua" :gz="formLabelAlign.gz"></Taihua>
        </template>
        <div
          class="form"
          v-if="
            platform('hzdpx') ||
            platform('qiye') ||
            platform('xtaq') ||
            (platform('zcaq') && formLabelAlign.gz == '大培训')
          "
        >
          <field
            label="验证码"
            fildType="input"
            v-model="formLabelAlign.codeChk"
            :filed_id="'codeChk'"
            :readonly="false"
          >
            <template #button>
              <div
                v-show="hascodeYes"
                @click.stop="hoveCode"
                style="
                  font-size: 14px;
                  background-color: #166aff;
                  color: #fff;
                  height: 40px;
                  width: 80px;
                  display: flex;
                  align-items: center;
                  justify-content: center;
                  position: absolute;
                  right: 0;
                  top: 0;
                "
              >
                发送验证码
              </div>
              <div
                v-show="!hascodeYes"
                style="
                  height: 40px;
                  width: 80px;
                  display: flex;
                  align-items: center;
                  justify-content: center;
                  position: absolute;
                  right: 0;
                  top: 0;
                  color: #000;
                "
              >
                {{ codeTime }}s
              </div>
            </template>
          </field>
        </div>
        <!-- http.indexOf('bosheng') != -1 &&
              formLabelAlign.gz == '燃气从业人员培训' -->
        <div
          class="form"
          v-if="
            (platform('bosheng') && formLabelAlign.gz == '燃气从业人员培训') ||
            platform('qiye')
          "
        >
          <field
            label="燃气主管部门"
            fildType="select"
            v-model="formLabelAlign.dep"
            :filed_id="'dep'"
            :readonly="true"
            :columns="options.dep"
            @change="changefiled"
          >
          </field>
        </div>
        <div class="form">
          <el-button
            @click="commit"
            style="background-color: #166aff; color: #fff; width: 100%"
          >
            {{
              platform("lyky") ||
              platform("xtaq") ||
              (platform("zcaq") && formLabelAlign.gz == "大培训")
                ? "提交并登录"
                : "提交"
            }}
          </el-button>
          <div
            v-if="setting && setting.PCwxpay == '是' && !platform('bosheng')"
            style="color: #f00; margin-top: 12px"
          >
            已报名未交费学员,请输入身份证、培训科目等信息进行缴费即可开通培训权限
          </div>
        </div>
      </div>
      <!-- 提示信息 -->
      <van-dialog
        v-model="tipShow"
        @cancel="tipShow = false"
        title="提示"
        v-if="str"
      >
        <div style="max-height: 70vh; overflow: auto">
          <el-input
            v-model="str"
            type="textarea"
            placeholder="请输入内容"
            :autosize="{ minRows: 2 }"
            resize="none"
            :readonly="true"
          ></el-input>
        </div>
      </van-dialog>
      <jf ref="jf" v-if="openid" :openid="openid"></jf>
    </div>
  </div>
</template>

<script>
import field from "@/components/field3.0/input.vue";
import upload from "@/components/Upload3.0/upload-moble.vue";
import sign from "@/components/sign3.0/index-mobel.vue";

import Taihua from "./components/taihua.vue";
import { mapGetters } from "vuex";

import apply from "@/components/model3.0/apply.js";
import jf from "./jf.vue";
import {
  setapplyid,
  getapplyid,
  delapplyid,
  setopenId,
  getopenId,
  delopenId,
  setstartInfo,
  delstartInfo,
  getstartInfo,
} from "@/utils/cookie.js";
import {
  applyAdd,
  getcode,
  getopenid,
  mpo,
  getapplyInfor,
} from "@/api/apply.js";
import { download } from "@/api/download.js";
export default {
  components: { upload, field, sign, Taihua, jf },
  computed: {
    ...mapGetters(["init", "http"]),
  },
  data() {
    return {
      loading: false,
      fromList: [], //后台返回的需要填写的字段
      formLabelAlign: {}, //提交的数据
      GZList: [], //工种列表
      gz: "",
      // subjectListTree:[],
      options: {}, //所有select组件的option
      setting: "", //后台设置
      subjectTittle: "",
      showsign: "",
      codeTime: 60,
      hascodeYes: true,
      subjectItem: {}, //当前选中的科目信息
      tipShow: false,
      str: "",
      photoApply: false, //是否开启身份证识别
      openid: "",
    };
  },
  watch: {
    gz(val) {
      let value = val;
      if (val == "危化品" || val == "高危安管") {
        value = "安全管理";
      }
      if (val == "一般行业") {
        value = "一般工贸";
      }
      this.fromList = [];
      this.formLabelAlign = { gz: value };
      this.applyListData(value);
    },
  },
  // created(){
  //     this.applyListData()
  // },
  methods: {
    ...apply.methods,
    //提交
    commit() {
      if (
        this.http.indexOf("taihua") == -1 ||
        (this.http.indexOf("taihua") != -1 &&
          this.formLabelAlign.gz != "学历提升")
      ) {
      } else {
        return this.commitA(); //太化
      }
      let formLabelAlign = JSON.parse(JSON.stringify(this.formLabelAlign));
      this.fromList.map((item) => {
        if (item.fitaber) {
          if (formLabelAlign[item.field_id]) {
            formLabelAlign[item.fitaber][item.field_id] =
              formLabelAlign[item.field_id];
          } else {
            formLabelAlign[item.fitaber][item.field_id] = "";
          }
          delete formLabelAlign[item.field_id];
        }
        if (item.field_type == "datetimeRange") {
          formLabelAlign[item.field_id] =
            formLabelAlign[item.field_id].join(",");
        }
      });
      delete formLabelAlign.id_card;
      if (this.openid) {
        formLabelAlign.openid = this.openid;
      }
      console.log(formLabelAlign, "9990999");
      // return
      if (this.platform("yali")) {
        if (formLabelAlign.gz == "危化品") {
          formLabelAlign.gz = "安全管理";
        }
        if (formLabelAlign.gz == "一般行业") {
          formLabelAlign.gz = "一般工贸";
        }
      }
      if (this.platform("dkaq") || this.platform("xcaq")) {
        if (formLabelAlign.gz == "高危安管") {
          formLabelAlign.gz = "安全管理";
        }
      }
      if (
        this.http.indexOf("bbxdf") != -1 ||
        this.http.indexOf("testtjy") != -1
      ) {
        if (this.formLabelAlign.extra.address == "") {
          return this.$hint.error("所在地区不能为空");
        }
      }
      if (
        this.platformAnhui() &&
        formLabelAlign.gz != "一般工贸" &&
        !formLabelAlign.extra.企业性质
      ) {
        return this.$hint.error("请选择企业性质");
      }
      if (
        this.platformAnhui() &&
        formLabelAlign.gz == "特种作业" &&
        !formLabelAlign.extra.注意事项
      ) {
        return this.$hint.error("注意事项请签名");
      }
      if (formLabelAlign.extra) {
        formLabelAlign.extra = JSON.stringify(formLabelAlign.extra);
      }
      if (formLabelAlign.cert) {
        formLabelAlign.cert = JSON.stringify(formLabelAlign.cert);
      }
      if (this.platform("bosheng") && formLabelAlign.gz == "燃气从业人员培训") {
        if (!formLabelAlign.dep) {
          return this.$hint.error("请选择燃气主管部门");
        }
      }
      if (
        (this.platform("hzdpx") ||
          this.platform("xtaq") ||
          (this.platform("zcaq") && formLabelAlign.gz == "大培训")) &&
        !formLabelAlign.codeChk
      ) {
        return this.$hint.error("请输入验证码");
      }
      let IDCard =
        /^[1-9]\d{5}(17|18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9X]$/; //身份证号校验
      let phone = /^1[3456789]\d{9}$/; //手机号校验
      // return
      for (
        let i = 0;
        i < this.fromList.filter((item) => !item.fitaber).length;
        i++
      ) {
        let items = this.fromList.filter((item) => !item.fitaber)[i];
        if (
          items.field_id == "exam_type" ||
          items.field_type == "download" ||
          items.field_id == "extra"
        ) {
          continue;
        }
        if (
          Boolean(items.selected) &&
          !formLabelAlign[items.field_id] &&
          items.field_id != "cert" &&
          items.passShow
        ) {
          if (items.field_id == "id_card") {
            if (!formLabelAlign["id_card_photo"]) {
              this.$hint.error("身份证人像面" + "不能为空");
              return;
            }
            if (!formLabelAlign["id_card_emblem"]) {
              this.$hint.error("身份证国徽面" + "不能为空");
              return;
            }
            continue;
          }
          this.$hint.error(items.label + "不能为空");
          return;
        }
        if (
          Boolean(items.selected) &&
          items.field_id == "cert" &&
          items.passShow
        ) {
          let obj = JSON.parse(formLabelAlign[items.field_id]);
          if (
            !formLabelAlign[items.field_id] ||
            formLabelAlign[items.field_id] == "[]"
          ) {
            this.$hint.error(items.label + "不能为空");
            return;
          }
          let list = JSON.parse(items.options);
          for (let j = 0; j < list.length; j++) {
            if (!obj[list[j].label]) {
              this.$hint.error(list[j].label + "不能为空");
              return;
            }
          }
        }
        if (
          items.field_id == "username" &&
          Boolean(items.selected) &&
          !IDCard.test(formLabelAlign.username)
        ) {
          this.$hint.error("身份证不合法");
          return;
        }
        if (
          items.field_id == "phone" &&
          Boolean(items.selected) &&
          !phone.test(formLabelAlign.phone)
        ) {
          this.$hint.error("手机号码不合法");
          return;
        }
        if (
          Boolean(items.selected) &&
          items.field_type == "datetimeRange" &&
          items.passShow
        ) {
          if (!formLabelAlign[items.field_id][0]) {
            return this.$hint.error(items.label + "开始时间不能为空");
          }
          if (!formLabelAlign[items.field_id][1]) {
            return this.$hint.error(items.label + "结束时间不能为空");
          }
        }
        if (items.field_type == "datetimeRange") {
          formLabelAlign[items.field_id] = JSON.stringify(
            formLabelAlign[items.field_id]
          );
        }
      }
      const obj = getstartInfo() ? JSON.parse(getstartInfo()) : {};
      formLabelAlign.admin_user_id = obj.admin_user_id ? obj.admin_user_id : "";
      formLabelAlign.depid = obj.depid ? obj.depid : "";
      formLabelAlign.dep = obj.dep ? obj.dep : "";
      formLabelAlign.grade = obj.grade ? obj.grade : "";
      if (formLabelAlign.dep) {
        formLabelAlign.dep = formLabelAlign.depid;
      }
      if (formLabelAlign.last_cert) {
        formLabelAlign.last_cert = JSON.stringify([formLabelAlign.last_cert]);
      }
      this.loading = true;
      applyAdd(formLabelAlign).then((res) => {
        if (getstartInfo()) {
          delstartInfo(); //删除之前的管理员信息
        }
        this.loading = false;
        if (res.code == 200) {
          if (this.setting.PCwxpay == "是") {
            // 判断是否有在线缴费的权限
            let msg =
              "请点击下方培训交费按钮进行交费，交费成功后即可开通培训权限进行学习";
            if (this.platform("bosheng")) {
              msg =
                "您已报名成功，该平台免费提供课程学习、题库练习、模拟考试、学习统计等服务功能，仅需支付平台运维费用";
            }
            if (Number(this.subjectItem.price)) {
              //判断该科目是否是在线缴费
              this.$dialog
                .confirm({
                  title: "提示",
                  message: msg,
                  confirmButtonText: "去交费",
                  beforeClose: (action, done) => {
                    if (action == "confirm") {
                      if (this.setting.payType == "H5") {
                        window.open(
                          this.http +
                            "/index/apply/mph5?applyid=" +
                            res.data.applyid
                        );
                        setapplyid(res.data.applyid);
                      } else {
                        setapplyid(res.data.applyid);
                        mpo({
                          applyid: res.data.applyid,
                          openid: this.openid,
                        }).then((resp) => {
                          if (resp.code == 200) {
                            WeixinJSBridge.invoke(
                              "getBrandWCPayRequest",
                              resp.data,
                              (res) => {
                                if (
                                  res.err_msg == "get_brand_wcpay_request:ok"
                                ) {
                                  this.$hint.success("支付成功");
                                  location.reload();
                                } else {
                                  delapplyid();
                                  this.$hint.error("支付失败");
                                }
                              }
                            );
                          } else {
                            delapplyid();
                            this.$hint.error(resp.msg);
                          }
                        });
                      }
                      done();
                    } else {
                      done();
                    }
                  },
                })
                .then(() => {
                  // this.$router.push('/')
                  // this.$hint.success('缴费成功')
                })
                .catch(() => {});
            } else {
              this.$dialog
                .confirm({
                  title: "提示",
                  message: "报名成功，管理员审核成功后即可开通培训权限",
                })
                .then(() => {
                  this.$router.push("/");
                })
                .catch(() => {});
            }
          } else {
            this.$dialog
              .confirm({
                title: "提示",
                message:
                  this.platform("hzdpx") ||
                  this.platform("xtaq") ||
                  (this.platform("zcaq") && formLabelAlign.gz == "大培训")
                    ? "报名成功,点击确定跳转至登陆界面"
                    : "报名成功，管理员审核成功后即可开通培训权限",
              })
              .then(() => {
                if (
                  this.platform("hzdpx") ||
                  this.platform("xtaq") ||
                  (this.platform("zcaq") && formLabelAlign.gz == "大培训")
                ) {
                  window.open(
                    this.http +
                      "/user/#/wxlogin?username=" +
                      formLabelAlign.username,
                    "_self"
                  );
                } else {
                  this.$router.push("/");
                }
              })
              .catch(() => {});
          }
        } else if (res.msg == "已经报过名了") {
          if (this.setting.PCwxpay == "是" && !this.platform("bosheng")) {
            // this.$refs.jf.open()
            let applyid = res.err.applyid;
            this.loading = true;
            getapplyInfor({
              username: formLabelAlign.username,
              subject_id: formLabelAlign.subject_id,
            }).then((res) => {
              if (res.code == 200) {
                if (res.data.length == 0) {
                  this.loading = false;
                  this.$dialog.confirm({
                    title: "提示",
                    message: "您已经报名并缴费，请到学员端登录学习",
                    confirmButtonText: "去登录",
                    cancelButtonText: "取消",
                    showClose: false,
                    beforeClose: (action, done) => {
                      if (action == "confirm") {
                        window.open(this.http + "/user", "_self");
                      }
                      done();
                    },
                  });
                } else {
                  this.loading = false;
                  this.$dialog.confirm({
                    title: "提示",
                    message: "该身份证号的该培训科目已报名未缴费，是否现在缴费",
                    confirmButtonText: "去缴费",
                    cancelButtonText: "取消",
                    showClose: false,
                    beforeClose: (action, done) => {
                      if (action == "confirm") {
                        this.$refs.jf.submit(formLabelAlign.username, applyid);
                      }
                      done();
                    },
                  });
                  return;
                }
              }
            });
          } else {
            this.$hint.error(res.msg);
          }
        } else {
          this.$hint.error(res.msg);
        }
      });
    },
    // 选择框回调
    changefiled(val, option) {
      if (option) {
        if (option.field_id == "subject_id") {
          this.subjectTittle = option.text.split("/")[0];
          this.formLabelAlign.subject_ids = option.ids;
          this.subjectItem = option.item;
          this.formLabelAlign.exam_type = option.text.includes("复审")
            ? "复审"
            : "初培";
          this.fromList.map((item) => {
            item.passShow = true;
            if (item.field_id == "last_cert") {
              if (this.formLabelAlign.exam_type.indexOf("初培") != -1) {
                item.passShow = false;
              } else {
                item.passShow = true;
              }
            }
            if (this.gz == "特种作业") {
              if (this.platformAnhui() || this.platform("qiye")) {
                if (item.field_id == "last_cert") {
                  if (this.formLabelAlign.exam_type.indexOf("初培") != -1) {
                    item.passShow = false;
                  } else {
                    item.passShow = true;
                  }
                }
                if (item.field_id == "qzsj") {
                  if (this.formLabelAlign.exam_type.indexOf("初培") != -1) {
                    item.passShow = false;
                  } else {
                    item.passShow = true;
                  }
                }
              } else if (!this.platform("lyjc")) {
                if (item.label == "现持证书信息") {
                  if (this.formLabelAlign.exam_type.indexOf("初培") != -1) {
                    item.passShow = false;
                  } else {
                    item.passShow = true;
                  }
                }
                if (item.label == "户口本" || item.label == "毕业证") {
                  if (this.formLabelAlign.exam_type.indexOf("复审") != -1) {
                    item.passShow = false;
                  } else {
                    item.passShow = true;
                  }
                }
              }
            }
            if (this.gz == "一般工贸") {
              if (this.platformAnhui()) {
                if (item.field_id == "last_cert") {
                  //初培证书
                  if (this.formLabelAlign.exam_type.indexOf("初培") != -1) {
                    item.passShow = false;
                  } else {
                    item.passShow = true;
                  }
                }
                if (item.field_id == "qzsj") {
                  if (this.formLabelAlign.exam_type.indexOf("初培") != -1) {
                    item.passShow = false;
                  } else {
                    item.passShow = true;
                  }
                }
              } else {
                if (
                  item.label == "安全合格证证号" ||
                  item.label == "截止日期"
                ) {
                  if (this.formLabelAlign.exam_type.indexOf("初培") != -1) {
                    item.passShow = false;
                  } else {
                    item.passShow = true;
                  }
                }
              }
            }
            if (this.gz == "安全管理" || this.gz == "高危安管") {
              if (this.platformAnhui()) {
                if (item.field_id == "zhicheng") {
                  if (option.text.indexOf("危险化学品生产单位") != -1) {
                    item.passShow = true;
                  } else {
                    item.passShow = false;
                  }
                }
                if (item.field_id == "edu_photo") {
                  if (option.text.indexOf("危险化学品生产单位") != -1) {
                    item.hint =
                      "毕业证和职称证选一个进行上传，须化工专业大专或中级职称以上证书";
                  } else {
                    item.hint = "毕业证和户口本选一个进行上传";
                  }
                }
              }
              if (item.field_id == "qzsj") {
                if (this.formLabelAlign.exam_type.indexOf("初培") != -1) {
                  item.passShow = false;
                } else {
                  item.passShow = true;
                }
              }
            }
            if (this.gz == "职业卫生") {
              if (this.platform("ataq")) {
                if (item.field_id == "training_record") {
                  if (this.formLabelAlign.exam_type.indexOf("初培") != -1) {
                    item.passShow = false;
                  } else {
                    item.passShow = true;
                  }
                }
              }
            }
            if (this.platform("yuhua")) {
              if (item.field_id == "edu_photo") {
                if (this.formLabelAlign.exam_type.indexOf("复审") != -1) {
                  item.passShow = false;
                } else {
                  item.passShow = true;
                }
              }
            }

            if (this.gz == "燃气从业人员培训" && this.platform("bosheng")) {
              if (item.field_id == "qzsj") {
                if (val.includes("新取证")) {
                  item.passShow = false;
                } else {
                  item.passShow = true;
                }
              }
              if (item.field_id == "cert_number") {
                if (val.includes("新取证")) {
                  item.passShow = false;
                } else {
                  item.passShow = true;
                }
              }
            }
          });
          this.$forceUpdate();
        }
        if (option.field_id == "region_id") {
          this.formLabelAlign[option.field_id] = option.ids;
        } else {
          this.formLabelAlign[option.field_id] = option.value;
        }
      }
    },
    //下载附件
    downFuled(files) {
      let MicroMessenger = navigator.userAgent.match(/MicroMessenger/i);
      if (files.length == 0) {
        return this.$hint.error("暂无附件下载~");
      }
      files.map((item) => {
        if (MicroMessenger) {
          download(item.src + "?mp.wexin.qq.com", item.name);
        } else {
          download(item.src, item.name);
        }
      });
    },
    //太化 提交
    commitA() {
      if (this.$refs.taihua.commit()) {
        let objA = this.$refs.taihua.commit()[0];
        let objB = this.$refs.taihua.commit()[1];
        this.loading = true;
        applyAdd({ ...objA, extra: JSON.stringify(objB) }).then((res) => {
          this.loading = false;
          if (res.code == 200) {
            this.$confirm(
              "报名成功，管理员审核成功后即可开通培训权限",
              "提示",
              {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "success",
                showClose: false,
              }
            )
              .then(() => {
                this.$router.push("/");
              })
              .catch(() => {});
          } else {
            this.$message.error(res.msg);
          }
        });
      }
    },
  },
  created() {
    if (this.$route.query.adminid) {
      setstartInfo(
        JSON.stringify({
          admin_user_id: this.$route.query.adminid,
          depid: this.$route.query.depid,
          dep: this.$route.query.dep,
          grade: this.$route.query.grade,
        })
      );
    } else {
      if (this.platformAnhui()) {
        setstartInfo(
          JSON.stringify({
            admin_user_id: "1106",
            depid: 1,
            dep: 1,
          })
        );
      } else {
        delstartInfo();
      }
    }
    apply.created.bind(this)();
    if (getapplyid()) {
      H5PayList({ applyid: getapplyid() }).then((resA) => {
        if (resA.code == 200) {
          if (resA.data != "支付成功") {
            this.$toast.fail(resA.data + ",请联系管理员");
            delapplyid();
          } else {
            this.$toast.success("支付成功,两秒后自动跳转到登录页面");
            delapplyid();
            setTimeout(() => {
              window.open(this.http + "/user", "_self");
            }, 2000);
          }
        } else {
          this.$toast.fail(resA.msg);
          delapplyid();
          done();
        }
      });
    } else {
      if (navigator.userAgent.match(/MicroMessenger/i)) {
        if (!getopenId()) {
          getcode(this.$route.query ? this.$route.query : "").then((res) => {
            // window.open(res.data,'_self')
            if (res.code == 200) {
              // this.iframeSrc=res.data.url
              setopenId(res.data.state);
              window.open(res.data.url, "_self");
            }
          });
        } else {
          getopenid({ state: getopenId() }).then((res) => {
            if (res.code == 200) {
              this.openid = res.data.openid;
              delopenId();
            } else {
              delopenId();
            }
          });
        }
      }
      if (this.setting.PCwxpay == "是") {
        if (this.setting.payType == "H5") {
          if (navigator.userAgent.match(/MicroMessenger/i)) {
            this.$dialog
              .confirm({
                title: "提示",
                message: "培训缴费学员请点击右上角···标识，选择在浏览器中打开",
              })
              .then(() => {})
              .catch(() => {});
          }
        } else {
          if (!navigator.userAgent.match(/MicroMessenger/i)) {
            this.$dialog
              .confirm({
                title: "提示",
                message:
                  "培训缴费学员请复制该链接在微信中打开，" + location.href,
              })
              .then(() => {})
              .catch(() => {});
          } else {
          }
        }
      }
    }
    if (this.setting.applyPhoto && this.setting.applyPhoto == "是") {
      this.photoApply = true;
    } else {
      this.photoApply = false;
    }
  },
};
</script>

<style lang="scss" scoped>
.applyHeade {
  height: 44px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #fff;
  padding: 0 12px;
  color: #000;
  font-size: 1rem;
  //   margin-bottom: 10px;
  width: 100%;
  position: relative;
  box-shadow: 0 2px 4px -2px rgba(0, 0, 0, 0.06);
  .back {
    // display: flex;
    // align-items: center;
    font-size: 1rem;
    color: #000;
    // float: left;
    position: absolute;
    left: 12px;
    i {
      font-size: 1rem;
      // font-weight: 600;
    }
  }

  .button {
    position: absolute;
    right: 12px;
    // font-size: 1rem;
    padding: 10px;
    background: rgba(22, 106, 255, 0.2);
    color: #166aff;
    border-color: rgba(22, 106, 255, 0.2);
    border-radius: 4px;
  }
}
.tableBody {
  height: calc(100% - 44px);
  padding: 12px 0;
  width: 100%;
  background: #fff;
  .form {
    padding: 12px 12px;
    margin-bottom: 1px;
    background: #fff;
    display: flex;
    align-items: flex-end;
  }
}
.require {
  color: #d0021b;
  font-size: 16px;
}
</style>